﻿using System.Net;
using System.Runtime.Serialization;

namespace Commands.Settings
{
    /// <summary>
    /// Class providing mail settings.
    /// </summary>
    [DataContract]
    public class MailSettings : ICredentialsByHost
    {
        public MailSettings(string username, string password, string pop3server, string smtpserver,
            bool ssl, int pop3port, int smtpport)
        {
            UserName = username;
            Password = password;
            Pop3Server = pop3server;
            SmtpServer = smtpserver;
            SSL = ssl;
            Pop3Port = pop3port;
            SmtpPort = smtpport;
        }

        public MailSettings(string username, string password, string pop3server, string smtpserver,
            bool ssl, int pop3port, int smtpport, string mailAddress, int maxAttachSize): this(username, password, pop3server, 
            smtpserver, ssl, pop3port, smtpport)
        {
            MailAddress = mailAddress;
            MaxAttachSize = maxAttachSize;
        }

        internal MailSettings()
        {
        }

        #region ICredentialsByHost members

        public NetworkCredential GetCredential(string host, int port, string authenticationType)
        {
            return new NetworkCredential(UserName, Password);
        }

        #endregion

        #region Pubic Properties

        [DataMember]
        public string MailAddress { get;  set; }

        [DataMember]
        public string UserName { get;  set; }

        [DataMember]
        public string Password { get;  set; }

        [DataMember]
        public string Pop3Server { get;  set; }

        [DataMember]
        public int Pop3Port { get; set; }

        [DataMember]
        public string SmtpServer { get;  set; }

        [DataMember]
        public int SmtpPort { get;  set; }

        [DataMember]
        public bool SSL { get;  set; }

        [DataMember]
        public string IMAPServer { get;  set; }

        [DataMember]
        public int IMAPPort { get; set; }

        [DataMember]
        public int MaxAttachSize { get; set; }

        #endregion

        #region Protected constants

        protected const int POP3_DEFAULT_DEFAULT_PORT = 110;
        protected const int IMAP_DEFAULT_PORT = 143;
        protected const int SMTP_DEFAULT_PORT = 25;

        #endregion
    }

    public class POP3Credentials : MailSettings
    {
        public POP3Credentials(string username, string password, string pop3server,
            string smtpserver)
            : base(username, password, pop3server, smtpserver, true,
                POP3_DEFAULT_DEFAULT_PORT, SMTP_DEFAULT_PORT)
        {
        }
    }

    //public class IMAPCredentials : Credentials
    //{
    //    public IMAPCredentials(string username, string password, string imapServer,
    //        string smtpServer)
    //        : base(username, password, imapServer, smtpServer, true,
    //            IMAP_DEFAULT_PORT, SMTP_DEFAULT_PORT)
    //    {
    //    }
    //}
}
